package com.wss.module.main.ui.main.fragment;

import com.wss.common.base.BaseMvpFragment;
import com.wss.common.base.adapter.listener.OnListItemClickListener;
import com.wss.common.bean.Template;
import com.wss.common.manage.AbilityToAbility;
import com.wss.module.main.ResourceTable;
import com.wss.module.main.ui.main.adapter.CaseAdapter;
import com.wss.module.main.ui.main.mvp.CasePresenter;
import com.wss.module.main.ui.main.mvp.contract.CaseContract;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.Lifecycle;
import ohos.agp.components.ListContainer;
import java.util.List;

public class CaseFragment extends BaseMvpFragment<CasePresenter> implements CaseContract.View {

    private ListContainer listContainer;

    public CaseFragment(Ability ability) {
        super(ability);
    }

    @Override
    protected CasePresenter createPresenter() {
        return new CasePresenter();
    }

    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_fragment_case;
    }

    @Override
    protected void initView() {
        listContainer = (ListContainer) getRootView()
                .findComponentById(ResourceTable.Id_recycle_view);
        getPresenter().start();
    }

    @Override
    public void refreshCaseList(List<Template> caseList) {
        listContainer.setItemProvider(new CaseAdapter(getContext(),
                caseList,
                new OnListItemClickListener<Template>() {
                    @Override
                    public void onItemClick(Template data, int position) {
                        AbilityToAbility.toAbility(ability, data);
                    }
                }));
    }

}
